#include <bits/stdc++.h>
using namespace std;

typedef struct LNode{
    int data;
    struct LNode *next;
}LNode, *LinkList;

void InitList(LinkList &L){
    L = new LNode;
    L->next = NULL;

}

void input(LinkList &L, int n){
    LNode *r;
    r = L;
    while(n--){
        LNode *p = new LNode;
        cin >> p->data;
        p->next = NULL;
        r->next = p;
        r = p;
    }

}

void output(LinkList L){
    int i = 0;
    LNode *p = L->next;
    while(p){
        if(i) cout << " ";
        cout << p->data;
        p = p->next;
        i = 1;
    }
}


void DivList_L(LinkList &LA, LinkList &LB, LinkList &LC) 
{
    InitList(LB);
    InitList(LC);
    double sum = 0;
    int cnt = 0;
    LNode *p = LA->next;
    while(p){
        sum += p->data;
        cnt++;
        p = p->next;
    }
    if(cnt == 0) return;
    double avg = sum / cnt;
    
    p = LA->next;
    while(p){
        LNode *t = p;
        p = p->next;
        if(fabs(t->data-avg) < 0.00001) delete t;
        else if(t->data < avg) {
            t->next = LB->next;
            LB->next = t;
        }else{
            t->next = LC->next;
            LC->next = t;
        } 
    }
} 

int main(){
    LinkList La, Lb, Lc;
    int num_a;
    cin >> num_a;
    InitList(La);
    input(La, num_a);
    DivList(La, Lb, Lc);
    output(Lb);
    cout << '\n';
    output(Lc);
    return 0;
}